// pages/consultation/workers/index.js
import {
  ApiRootUrl,
  apiList,
  IMG_PATH
} from '../../../config/index.js'
import Dialog from '../../../@vant/weapp/dialog/dialog';
import {
  request,formatStringTime
} from "../../../utils/util.js"
import Toast from '../../../@vant/weapp/toast/toast';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isFinish:false,
    labourMicroList:[],
    active: 0,
    pageNumber:1,
    height: 0,
    tabList: [{
      title: '处理中',
    }, {
      title: '已办结',
    }],
    statusBarHeight:'',
    pendingList: [],
    titlename:'处理中'
  },

  tabClick(event) {
    this.setData({
      active: event.detail.index,
      pageNumber:1,
      titlename:this.data.tabList[event.detail.index].title
    })
    this.getLaodong(this.data.active)
  },
  updateTask(){

  },
  goListDetail(e){
    console.log(e);
    let id=e.currentTarget.dataset.id
    let code=e.currentTarget.dataset.code
    console.log(id);
    wx.navigateTo({
      url: `/recruitmentest/pages/consultation/listdetail/listdetail?id=${id}&code=${code}`,
    })
  },
  newaddClick(){
 
   wx.navigateTo({
     url: '../../consultation/addnew/index',
   })
  },
  loadMore(e) {
    if (this.data.active == 0) { // 处理中

        this.setData({
          isLoad:true
        })
        this.getLaodong(this.data.active)
  
    } else { //已办结
     
        this.setData({
          isLoad:true
        })
        this.getLaodong(this.data.active)
     
    }
  },
  getLaodong(active){
    let self=this
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });
    
    let params={
      isDeal:active,
    }
    wx.request({
      url: `${ApiRootUrl}/labourMicro/queryLabourMicro`,
      method: 'POST',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      success(res) {
        if(res.data.code == 20000){
          if(active==0){
            self.setData({
              isFinish:false
            })
          }else{
            self.setData({
              isFinish:true
            })
          }
          Toast.clear();
          console.log(res.data.data);
          self.setData({
            labourMicroList:res.data.data.list
          })
        }else{
          Toast.clear();
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res){
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },
  queryDetails(e){
    console.log(e);
    
    let id=e.target.dataset.id
    let code=e.target.dataset.code
    console.log(id);
    wx.navigateTo({
      url: `/recruitmentest/pages/consultation/technological/technological?id=${id}&code=${code}`,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let query = wx.createSelectorQuery();
    query.select('.content').boundingClientRect(rect => {
      let height = rect.height;
      this.setData({
        // statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
        height: wx.getSystemInfoSync().windowHeight - height - 50,
        sourceShowColumns:app.globalData.companyList||[],
        userinfo:wx.getStorageSync('userinfo')
      })
    }).exec();
    this.getLaodong(this.data.active)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})